package source;

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;

public class doSmsSend implements Runnable {
    private String shortcodeNumber;
    private String smsContent;
    public doSmsSend(String number, String msg) {
        shortcodeNumber = number;
        smsContent = msg;
    }
    
    public void doSend(String number,String message)
    {
        String address = "sms://"+number;
        MessageConnection connection = null;
        try {
            connection = (MessageConnection) Connector.open(address);
            TextMessage text =
                (TextMessage)connection.newMessage(MessageConnection.TEXT_MESSAGE);
            text.setPayloadText(message);
            connection.send(text);
        } catch (Exception err) {
            err.printStackTrace();
        }

        if (connection != null) {
            try {
                connection.close();
            } catch (Exception i) {
                i.printStackTrace();
            }
        }
    }

    public void run() {
        try {
            Thread.sleep(2000);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        doSend(shortcodeNumber, smsContent);
    }
}
